package com.camera.yl.decoration

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * Cyber主题网格装饰器
 * 对应HTML中的cyber-grid效果
 */
class CyberGridDecoration(
    private val gridSize: Int = 20, // 网格大小，对应HTML中的20px
    private val gridColor: Int = 0x1A00FFFF // 青色网格线，透明度10%
) : RecyclerView.ItemDecoration() {

    private val paint = Paint().apply {
        color = gridColor
        strokeWidth = 1f
        style = Paint.Style.STROKE
        isAntiAlias = true
    }

    override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        super.onDraw(c, parent, state)
        
        val width = parent.width
        val height = parent.height
        
        // 转换dp到px
        val gridSizePx = (gridSize * parent.context.resources.displayMetrics.density).toInt()
        
        // 绘制垂直网格线
        var x = 0f
        while (x <= width) {
            c.drawLine(x, 0f, x, height.toFloat(), paint)
            x += gridSizePx
        }
        
        // 绘制水平网格线  
        var y = 0f
        while (y <= height) {
            c.drawLine(0f, y, width.toFloat(), y, paint)
            y += gridSizePx
        }
    }
} 